<?php

require_once("../../inc/connect.php");
$deleteRowTable = $_POST['tableSelect'];


$result_delete = mysql_query("DROP TABLE table$deleteRowTable");

if(!$result_delete ) {
	$response = "alert('ไม่สามารถลบโต๊ะหมายเลข ' + $deleteRowTable + ' ได้');";

} else {
	$result_reservation = mysql_query("SELECT * FROM reservation WHERE table_id ='$deleteRowTable'");

	if(mysql_num_rows($result_reservation) > 0) {
		while($row = mysql_fetch_array($result_reservation)) {
			$ref_table = $row['table_id'];
			$result1 = mysql_query("DELETE FROM reservation WHERE table_id = '$ref_table'");
		}
	}

	$response = "window.location.reload();";
}

mysql_close($con);

header("content-type:text/javascript; charset=utf-8");
echo $response;

?>